package com.admin.server.domain;

import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.admin.share.model.MenuDTO;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable
public class Menu {

	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
	
	@Persistent
	private String menu;
	@Persistent
	private String parametro;
	@Persistent
	private Boolean haschildren;
	@Persistent
	private Integer tipo;
	
	@Persistent
	private Menu parent;
	
	@Persistent(mappedBy="parent")
	@Element(dependent = "true")
    private Set<Menu> children = new HashSet<Menu>();

	public Key getKey() {
		return key;
	}

	public String getMenu() {
		return menu;
	}

	public void setMenu(String menu) {
		this.menu = menu;
	}

	public String getParametro() {
		return parametro;
	}

	public void setParametro(String parametro) {
		this.parametro = parametro;
	}

	public Boolean getHaschildren() {
		return haschildren;
	}

	public void setHaschildren(Boolean haschildren) {
		this.haschildren = haschildren;
	}

	public Integer getTipo() {
		return tipo;
	}

	public void setTipo(Integer tipo) {
		this.tipo = tipo;
	}
	
	public Menu getParent(){
		return parent;
	}
	
	public void addChildren(Menu mnu){
		children.add(mnu);
	}
	
	public Set<Menu> getChildren(){
		return children;
	}
	
	public MenuDTO toDTO(){
		MenuDTO menuDTO = new MenuDTO();
		menuDTO.setId(KeyFactory.keyToString(this.getKey()));
		menuDTO.setMenu(this.getMenu());
		menuDTO.setParametro(this.getParametro());
		menuDTO.setTipo(this.getTipo());
		menuDTO.setHaschildren(this.getHaschildren());		
		return menuDTO;
	}
	
	
	
}
